package com.game.web.controller.game;

import com.game.common.annotation.Log;
import com.game.common.core.controller.BaseController;
import com.game.common.core.domain.AjaxResult;
import com.game.common.core.page.TableDataInfo;
import com.game.common.enums.BusinessType;
import com.game.common.utils.poi.ExcelUtil;
import com.game.system.domain.game.GameTemplate;
import com.game.system.service.IGameTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 游戏模板Controller
 *
 * @author Mr.Liu
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/game/template")
public class GameTemplateController extends BaseController
{
    @Autowired
    private IGameTemplateService gameTemplateService;

    /**
     * 查询游戏模板列表
     */
    @PreAuthorize("@ss.hasPermi('game:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(GameTemplate gameTemplate)
    {
        startPage();
        List<GameTemplate> list = gameTemplateService.selectGameTemplateList(gameTemplate);
        return getDataTable(list);
    }

    /**
     * 导出游戏模板列表
     */
    @PreAuthorize("@ss.hasPermi('game:template:export')")
    @Log(title = "游戏模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GameTemplate gameTemplate)
    {
        List<GameTemplate> list = gameTemplateService.selectGameTemplateList(gameTemplate);
        ExcelUtil<GameTemplate> util = new ExcelUtil<GameTemplate>(GameTemplate.class);
        util.exportExcel(response, list, "游戏模板数据");
    }

    /**
     * 获取游戏模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('game:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gameTemplateService.selectGameTemplateById(id));
    }

    /**
     * 新增游戏模板
     */
    @PreAuthorize("@ss.hasPermi('game:template:add')")
    @Log(title = "游戏模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GameTemplate gameTemplate)
    {
        return toAjax(gameTemplateService.insertGameTemplate(gameTemplate));
    }

    /**
     * 修改游戏模板
     */
    @PreAuthorize("@ss.hasPermi('game:template:edit')")
    @Log(title = "游戏模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GameTemplate gameTemplate)
    {
        return toAjax(gameTemplateService.updateGameTemplate(gameTemplate));
    }

    /**
     * 删除游戏模板
     */
    @PreAuthorize("@ss.hasPermi('game:template:remove')")
    @Log(title = "游戏模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gameTemplateService.deleteGameTemplateByIds(ids));
    }
}
